<?php
define('IN_ECS', true);
//define('DEBUG',false);
set_time_limit(0); 
header("Content-Type: text/html; charset=utf-8");
//function charCodeAt($code,$i){
//	preg_match_all("/[\x80-\xff]?./",$code,$ar);
//	$c='';
//	$c=utf8_unicode(iconv("GB2312","UTF-8",$ar[0][$i]));
//	return $c;
//}
 $m = "啊儿";
 $p = "/^.{3,3}儿$/";
 preg_match($p, trim( $m), $n);
 //echo preg_replace($p,'',trim( $m));
 print_r($n);
 
 

@require_once "./Common/init.php";
	for($i=0;$i<10;) { 
		$do = new CurlUtil("http://www.acfun.tv/content_view.aspx?contentId=888888");
		$do->init();
		$output = $do->getBody();
		echo $output;
		$cc = @ explode(',', substr($output, 1, strlen($output) - 2));
		$arr = json_decode($output);
		//echo $arr[1];
		if($arr[1]===0) {
			//echo "ssss";
			$cookes_file = ROOT_PATH . "/Temp/" .md5(""."") . ".dat";
			//if (!file_exists($cookes_file)) {
				$post_fields = "username=" . URLEncode("") . "&password=" . URLEncode("3088100");
				$do = new CurlUtil("http://www.acfun.tv/login.aspx");
				$do->cookie_file = $cookes_file;
				$do->post_fields = $post_fields;
				$do->header = 1;
				$do->init();
				$out = $do->getBody();
			//}
			$post_fields2 = "text=" . URLEncode("~~~=_=~~~") . "&contentId=888888";
			$do = new CurlUtil("http://www.acfun.tv/comment.aspx");
			$do->cookie_file = $cookes_file;
			$do->post_fields = $post_fields2;
			$do->init();
			$output = $do->getBody();
			echo $output;
			break;
		} 
		sleep(1);
	}
return ;
//echo charCodeAt("aedf",1);
//echo  $f;
//echo exec("node ".$f);
//echo $a = strtotime("2013-06-01 01:00:00");
//echo 'substr("1234567",-1,2)'.substr("1234567",-2,2);
$user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)";
$url ="https://dynamic.12306.cn/otsweb/passCodeNewAction.do?module=login&rand=sjrand";
//$url ="https://secure.bilibili.tv/captcha";
 $cookes_file = ROOT_PATH .("12306") . ".dat";
 
 
 $url = "https://dynamic.12306.cn/otsweb/order/myOrderAction.do?method=initRefundLogin";
  $fp = fopen('./test1.txt','wb');
 $do = new CurlUtil($url);
 $do->cookie_file = $cookes_file;
 $do->fp = $fp;
 $do->https = true;
 $do->header = 1;
 $do->userAgent = $user_agent;
 $do->init();
 $do->getBody();
 fclose($fp);
if(!$_GET['test']) {
 $fp = fopen('./test.jpeg','wb');
 $do = new CurlUtil($url);
 $do->cookie_file = $cookes_file;
 $do->fp = $fp;
 $do->https = true;
 $do->userAgent = $user_agent;
 $do->init();
 $do->getBody();
 fclose($fp);
} else { 
// if($_GET['test']) { 
 $cookes_file = ROOT_PATH .("12306") . ".dat";
 $fp = fopen('./test10306.txt','wb');
 $url = "https://dynamic.12306.cn/otsweb/loginAction.do?method=init";
  
 $do = new CurlUtil($url);
 $do->fp = $fp;
 $do->https = true;
 $do->url=$url;
 $do->header =1;
  $do->cookie_file = $cookes_file;
 $do->encoding = 'gzip,deflate';
 $do->userAgent = $user_agent;
 $do->init();
$do->getBody();
fclose($fp);
$out =  file_get_contents('./test10306.txt');
$p = '/<script[^>]*src=\"(\/otsweb\/dynamicJsAction\.do\?jsversion=.*?&method=loginJs)"/si';

preg_match($p, $out, $m);
		//	print_r($m);
 $fp = fopen('./test10306.txt','wb');
$url = "https://dynamic.12306.cn".$m[1];
$do = new CurlUtil($url);
 $do->fp = $fp;
 $do->https = true;
 $do->url=$url;
// $do->header =1;
  $do->cookie_file = $cookes_file;
 $do->encoding = 'gzip,deflate';
 $do->userAgent = $user_agent;
 $do->init();
$do->getBody();
fclose($fp);
$out =  file_get_contents('./test10306.txt');
$p= '/gc\(\)\{var key=\'(.*?)\';var/si';
preg_match($p, $out, $n);
//print_r($n);
$key = $n[1];
$value = "1111";
 $f = ROOT_PATH."Node/node.js ".$value." ".$key;
$value =  exec("node ".$f);
echo $value;

$fp = fopen('./test10306.txt','wb');
$url = "https://dynamic.12306.cn/otsweb/loginAction.do?method=loginAysnSuggest";
$do = new CurlUtil($url);
 $do->fp = $fp;
 $do->https = true;
 $do->url=$url;
// $do->header =1;
  $do->cookie_file = $cookes_file;
 $do->encoding = 'gzip,deflate';
 $do->userAgent = $user_agent;
 $do->init();
$do->getBody();
fclose($fp);
$out =  file_get_contents('./test10306.txt');
$re = @json_decode($out);
print_r($re);

	$post_fields = "loginRand=".$re->loginRand."&refundLogin=Y&refundFlag=".$re->randError."&loginUser.user_name=&user.password=&randCode=".$_POST['vcode']."&".URLEncode($key)."=".URLEncode($value);
	echo $post_fields;
	 $fp = fopen('./test10306.txt','wb');
	$url = "https://dynamic.12306.cn/otsweb/loginAction.do?method=login";
	$do = new CurlUtil($url);
	 $do->fp = $fp;
	 $do->https = true;
	 $do->url=$url;
	$do->header =1;
	  $do->cookie_file = $cookes_file;
	  $do->post_fields = $post_fields;
	 $do->encoding = 'gzip,deflate';
	 $do->userAgent = $user_agent;
	 $do->init();
	$do->getBody();
	fclose($fp);
	return;
}
//}
/*
 
 if($_GET['test']) {  
	 $fp = fopen('./test.txt','wb');
	 $cookes_file = ROOT_PATH . "/Temp/" .("yaya3") . ".dat";
	 $do = new CurlUtil("https://passport.baidu.com/v2/api/?getapi&tpl=mn&apiver=v3&tt=".time()."&class=login&logintype=dialogLogin&callback=");
	 $do->cookie_file = $cookes_file;
	 $do->fp = $fp;
	 $do->https = true;
	 $do->init();
	 $do->getBody();
	 fclose($fp);
	 $a = file_get_contents('./test.txt');
	 $a = str_replace("'","\"",$a);
	 $re = @json_decode($a);
	 print_r($re);
	 $token = $re->data->token;
	 echo $token;
	$post_fields = "keeptime=2592000&vdcode=".$_POST['vcode']."&act=login&gourl=".URLEncode("")."&userid=" . URLEncode("") . "&pwd=" . URLEncode("");
 	$post_fields = "token=".$token."&tpl=mn&apiver=v3&isPhone=false&safeflg=0&splogin=rate&mem_pass=on&ppui_logintime=37976".
 	"&username=".URLEncode("懒猫小猿")."&password=".URLEncode("wudigood");
 	$fp = fopen('./test1.txt','wb');
 	$do = new CurlUtil("https://passport.baidu.com/v2/api/?login");
	$do->cookie_file = $cookes_file;
	$do->https = true;
	$do->post_fields = $post_fields;
	$do->fp=$fp;
	$do->header = 1;
	$do->init();
	$do->getBody();
	 fclose($fp);
	//echo $out;
 } else {
 	$kw = "丫丫";
 	$cookes_file = ROOT_PATH . "/Temp/" .("yaya3") . ".dat";
 	//$post_fields = "keeptime=2592000&vdcode=".$_POST['vcode']."&act=login&gourl=".URLEncode("")."&userid=" . URLEncode("") . "&pwd=" . URLEncode("");
			//$fp = fopen('./test.txt','wb');
			$do = new CurlUtil("http://tieba.baidu.com/f?kw=".URLEncode(mb_convert_encoding(trim($kw), 'GB2312', 'UTF-8'))."&fr=index");
		//	echo "http://tieba.baidu.com/f?kw=".URLEncode($kw)."&fr=index";
			$do->cookie_file = $cookes_file;
			//$do->https = true;
			//$do->post_fields = $post_fields;
			//$do->fp=$fp;
		//	$do->header = 1;
			$do->init();
			$out = $do->getBody();
			$out = mb_convert_encoding($out, 'UTF-8', 'GB2312');
			//echo $out;
// 			fclose($fp);
 			$p = '/<script>PageData\.tbs.*?\"(.*?)\".*?PageData/si';
//			
//			$a = file_get_contents('./test.txt');
			preg_match($p, $out, $m);
			//print_r($m);
			$post_fields = "kw=".URLEncode($kw)."&tbs=".$m[1]."&ie=utf-8";
			$do = new CurlUtil("http://tieba.baidu.com/sign/add");
			$do->cookie_file = $cookes_file;
			$do->post_fields = $post_fields;
			$do->init();
			$out = $do->getBody();
			$re = @json_decode($out);
			print_r($re);
 	return;
 }
 
// $ch = curl_init('https://secure.bilibili.tv/captcha?r='.time());
//       $fp = fopen('./test1.png','wb');
        
        // set URL and other appropriate options
//        $options = array(CURLOPT_FILE => $fp,
//                         CURLOPT_HEADER => 0,
//                         CURLOPT_FOLLOWLOCATION => 1,
//                         CURLOPT_TIMEOUT => 60); // 1 minute timeout (should be enough)
//        
//        curl_setopt_array($ch, $options);
//        
//        curl_exec($ch);
//        curl_close($ch);
//        fclose($fp);
//        
// 	$hander = curl_init();
//    $fp = fopen(time().'test.png','wb');
//	$url = 'https://secure.bilibili.tv/captcha?r='.time();
//    curl_setopt($hander,CURLOPT_URL,$url);
//    curl_setopt($hander,CURLOPT_FILE,$fp);
//    //curl_setopt($hander,CURLOPT_HEADER,0);
//    //curl_setopt($hander,CURLOPT_FOLLOWLOCATION,1);
//    //curl_setopt($hander,CURLOPT_RETURNTRANSFER,false);//以数据流的方式返回数据,当为false是直接显示出来
//    //curl_setopt($hander,CURLOPT_TIMEOUT,60);
//
//    /*$options = array(
//        CURLOPT_URL=> 'http://yi1.com.cn/content/uploadfile/201106/thum-f3ccdd27d2000e3f9255a7e3e2c4880020110622095243.jpg',
//        CURLOPT_FILE => $fp,
//        CURLOPT_HEADER => 0,
//        CURLOPT_FOLLOWLOCATION => 1,
//        CURLOPT_TIMEOUT => 60
//    );
//    curl_setopt_array($hander, $options);
//    */
//	curl_setopt($hander, CURLOPT_SSL_VERIFYPEER, FALSE);
//	curl_setopt($hander, CURLOPT_SSL_VERIFYHOST, FALSE);
//    curl_exec($hander);
//    curl_close($hander);
//    fclose($fp);
        
 /*
$url = 'https://yande.re/pool/show/30';
$body = file_get_contents($url);
$p = '/<li .*?<div class=\"inner\".*?<a[^>]+class=\"thumb\".*?href=\"([^>\"]+)\"/si';
preg_match_all($p, $body, $m);
//print_r($m[1]);
set_time_limit(1800);
for($i=0;$i<count($m[1]);$i++) {
	$body = file_get_contents("https://yande.re".$m[1][$i]);
	//echo "https://yande.re".$m[1][$i];
	$p1 = '/<a[^>]+href=\"([^>\"]+)\"[^>]+id=\"png\"/si';
	preg_match($p1,$body,$n);
	//print_r($n);
	echo "\n".$n[1];
	
}
echo "\n";
//$ch = curl_init(); 
//curl_setopt($ch, CURLOPT_URL, $url); 
//curl_setopt($ch, CURLOPT_VERBOSE, true); 
//curl_setopt($ch, CURLOPT_HEADER, true);
////curl_setopt($ch, CURLOPT_NOBODY, true);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
//curl_setopt($ch, CURLOPT_TIMEOUT, 20); 
//curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
//$ret = curl_exec($ch); 
//$info = curl_getinfo($ch); 
//curl_close($ch);
//print_r($info);
//echo $ret;
//require_once "./Common/init.php";
//echo substr( "写进文本中的内容",6,3);
//print_r(ereg_replace('[u4e00-u9fa5]','','写进文本中的内容'));
//substr($str,0,2);
//$str = "abc3";  //写进文本中的内容
//$filename = "data.dat"; //保存的位置及文件名称
//$fp = fopen($filename, "a") or exit("error"); //试著打开文件, 失败就弹出error讯息
//fwrite($fp, $str); //开始写进内容
//fclose($fp);  
////include('./include/phpqrcode/phpqrcode.php'); 
//
//	$post_fields = "requestContent=" . URLEncode("废物分解为") ;// "&pwpwd=" . URLEncode("dwerdwer")."&jumpurl=http://";
//	$cookes_file = ROOT_PATH . "/Temp/"  . "test.dat";
/*	$do = new CurlUtil("http://tieba.baidu.com/p/1609777293?pn=9999");
	//$do->cookie_file = $cookes_file;
//	$do->post_fields = $post_fields;
	$do->init();
	$out = $do->getBody();
	$match_name = '/(<div[^>]*class=\"d_post_content j_d_post_content\"[^>]*>)(([^<]+|<(?!\/?div[^>]*>)|<div[^>]*>(?>(?3))*<\/div>)*)(<\/div>)/si';
	preg_match_all($match_name, $out, $m);
	print_r($m[2]);
	//echo $out;
//	$do = new CurlUtil("http://222.73.115.170/robot/demo/wap/wap-demo.action?requestContent=pp");
//	$do->cookie_file = $cookes_file;
////	$do->post_fields = $post_fields2;
//	$do->init();
//	$output = $do->getBody();
//	echo $output;
//	$p = '/<a[^>]*href=\"tel[^>0-9]*([0-9]+)\"/si';
//	preg_match($p, $output, $m);
//	echo $m[1];
/*
 * Created on 2012-11-28
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 
$post_fields = "username=".urlencode("")."&password=".urlencode("");
 $ch = curl_init();
//curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false); 

curl_setopt($ch, CURLOPT_URL, 'http://www.acfun.tv/login.aspx'); 
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1); 

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
curl_setopt($ch, CURLOPT_COOKIEJAR, "D:/JB/xampp/htdocs/SoniaRobot/Temp/aaa.dat");
 $output = curl_exec($ch);
 
 echo $output."22";
 
 		curl_close($ch);*/
 
 //echo strncmp("20121209003656","99999999210000",14);
 //$data = '丫丫';
   // 生成的文件名
  
   // 纠错级别：L、M、Q、H
   //$errorCorrectionLevel = 'L'; 
  // $filename ='test.png';
   // 点的大小：1到10
  // $matrixPointSize = 4; 
   //QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
   
//   $a = "ค้้";
//   echo strlen($a);
//   echo substr($a,8,1);
//
  
   
    //这个curl是因为官方每次请求都有唯一的COOKIE，我们必须先把COOKIE拿出来，不然会一直返回“HI” 
//    $mess = $_POST[Message];   
//    $url = "http://www.simsimi.com/talk.htm?lc=ch"; 
//    $ch = curl_init();    
//    curl_setopt($ch, CURLOPT_URL, $url);    
//    curl_setopt($ch, CURLOPT_HEADER, 1);    
//    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    
//    $content = curl_exec($ch);    
//    curl_close($ch);    
//    list($header, $body) = explode("\r\n\r\n", $content);    
//    preg_match("/set\-cookie:([^\r\n]*)/i", $header, $matches);      
//    $cookie = $matches[1];    
//   
//   
//    $urll = 'http://www.simsimi.com/func/req?msg='+$mess+'&lc=ch';    
//        
//    // 这个CURL就是模拟发起请求咯，直接返回的就是JSON    
//   
//    $ch = curl_init();    
//    curl_setopt($ch, CURLOPT_URL, $urll);    
//    curl_setopt($ch, CURLOPT_HEADER, 0);    
//    curl_setopt($ch, CURLOPT_REFERER, "http://www.simsimi.com/talk.htm?lc=ch");    
//    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    
//    curl_setopt($ch, CURLOPT_COOKIE, $cookie);    
//    $content = curl_exec($ch);    
//    curl_close($ch);
//    $json = json_decode($content, 1);   
//    if (isset($json['response'])) {   
//        $reply = $json['response'];   
//    }
//    echo   $reply;  

?>

<form action="test.php?test=true" method="post">
<img src='test.jpeg' ></img>
	<input type="text" class="text" name="Event" value="ReceiveClusterIM" /> <br />
	<textarea name="Message"  rows="10" cols="50" wrap="off"> </textarea>  <br />
	<input type="text" class="text" name="ClusterNum" value="111531966" /> <br />
	<input type="text" class="text" name="Sender" value="261589289" /> <br />
	<input type="text" class="text" name="ApiPort" value="6903" /> <br />
	<input type="text" class="text" name="vcode" value="" /> <br />
	<input type="submit" class="submit button" />
</form>
